{extend name="public:base"}
{block name="main"}
<div class="demoTable">
  <a  href="{:Url('modelinfo')}" class="layui-btn" data-type="reload" lay-filter="cateadd" lay-submit>添加模型</a>
</div>
<table class="layui-table" lay-data="{height:650,url:'{:Url('modellist')}', page:true, id:'newslist'}" lay-filter="table">
  <thead>
    <tr>
      <th lay-data="{field:'px', width:80, sort: true}">排序</th>
      <th lay-data="{field:'modelid', width:80, sort: true}">ID</th>
      <th lay-data="{field:'name', width:130}">模型名称</th>
      <th lay-data="{field:'type', width:120}">类型</th>
      <th lay-data="{field:'template', width:200}">模板</th>
      <th lay-data="{field:'addtime', width:180}">添加时间</th>
      <th lay-data="{fixed: 'right', width:350,  toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>


<script type="text/html" id="barDemo">
  
  <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
   
  <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
  {{#  if(d.catetype == '单页面'){ }}
      <a class="layui-btn layui-btn-sm" lay-event="editpage">页面编辑</a>
  {{#  } }} 
</script>

<script>
layui.use(['table','laydate','form'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  var form = layui.form;
   laydate.render({
      elem: '#start',
      max: 0
   });
    laydate.render({
      elem: '#end',
      max: 1
   });
   
  var $ = layui.$;


  table.on('tool(table)', function(obj){
    var data = obj.data;

   if(obj.event === 'del'){
      layer.confirm('真的删除本条数据吗？', function(index){

        $.post("{:Url('modelinfo')}",{'modelid': data.modelid},function(data){
           if(data=='1'){
              alert();
              obj.del();
              layer.close(index);
           }else{
             alert("删除失败请重试！");
           }
        })
        
      });
    } else if(obj.event === 'edit'){
        location.href="/admin.php/cate/modelinfo/modelid/"+data.modelid;
      //layer.alert('编辑行：<br>'+ JSON.stringify(data))
    } else if(obj.event === 'editpage'){
        location.href="/admin.php/cate/pageinfo/modelid/"+data.modelid;
      //layer.alert('编辑行：<br>'+ JSON.stringify(data))
    }

  });


});

</script>
{/block}